import * as server from "@minecraft/server";
import * as realm_property from "../system/realm_property";
import * as derived_tools from "../system/derived_tools";
import * as native_tools from "../system/native_tools";
import * as achieve_plan from "../system/achieve_plan";
import * as math_tools from "../system/math_tools";
export function Supply(block, value) {
    const energy = realm_property.AlterEnergy(block, value, true);
    derived_tools.AlterMessageNotify('<§l§b 能量节点 §r>§s 星尘力产出§r', block, { text: '<§l§d 星尘力 §r> : §l§u' + energy[1] + '§r' });
}
;
export function Tank(object) {
    const target = object.above();
    if (!target || target.isAir || !target.isValid())
        return;
    native_tools.TrySetPermutation(target, 'STATE:stage', 1);
}
;
function EnergyAllocation(block, offset) {
    for (let index = 1; index < 6; index++) {
        const target = block.offset(math_tools.Vector.scale(offset, index));
        if (!target || !target.hasTag('data_tag:energy_module.allocation'))
            continue;
        const states = target.permutation;
        if (states.getState('STATE:output') == 1)
            continue;
        target.setPermutation(states.withState('STATE:output', 1));
    }
}
;
function CheckAllocation(block) {
    const entry = [block.east(), block.west(), block.north(), block.south()];
    for (let index = 0; index < entry.length; index++) {
        if (entry[index]?.hasTag('data_tag:energy_module.allocation'))
            return true;
    }
    ;
    return false;
}
;
export function Wind(block) {
    const permutation = block.permutation;
    const current = permutation.getState('STATE:stage');
    if (!CheckAllocation(block))
        return;
    if (block.y > 200 || block.y < 64)
        return;
    const threshold = Math.floor(9 - ((block.y - 64) / 15));
    if (current < threshold)
        return;
    if (achieve_plan.ControlEventTrigger.BlockToken(block.typeId, block, 60)) {
        const molang = new server.MolangVariableMap();
        molang.setFloat('variable.direction', 2);
        molang.setFloat('variable.size', 16);
        native_tools.TrySpawnParticle(block.dimension, 'scripts:path_round', math_tools.Vector.add(block.location, math_tools.Vector.CONSTANT_HALF), molang);
        native_tools.TrySpawnParticle(block.dimension, 'scripts:path_label', math_tools.Vector.add(block.location, math_tools.Vector.CONSTANT_HALF), molang);
    }
    ;
    switch (permutation.getState('minecraft:cardinal_direction')) {
        case 'south':
            EnergyAllocation(block, math_tools.Vector.CONSTANT_SOUTH);
            break;
        case 'north':
            EnergyAllocation(block, math_tools.Vector.CONSTANT_NORTH);
            break;
        case 'east':
            EnergyAllocation(block, math_tools.Vector.CONSTANT_EAST);
            break;
        case 'west':
            EnergyAllocation(block, math_tools.Vector.CONSTANT_WEST);
            break;
        default: break;
    }
    ;
    native_tools.TrySetPermutation(block, 'STATE:stage', 9);
}
;
export function Water(block) {
    const permutation = block.permutation;
    if (!CheckAllocation(block))
        return;
    native_tools.TrySetPermutation(block, 'STATE:stage', 0);
    switch (permutation.getState('minecraft:cardinal_direction')) {
        case 'south':
            EnergyAllocation(block, math_tools.Vector.CONSTANT_SOUTH);
            break;
        case 'north':
            EnergyAllocation(block, math_tools.Vector.CONSTANT_NORTH);
            break;
        case 'east':
            EnergyAllocation(block, math_tools.Vector.CONSTANT_EAST);
            break;
        case 'west':
            EnergyAllocation(block, math_tools.Vector.CONSTANT_WEST);
            break;
        default: break;
    }
    ;
    achieve_plan.SprayParticleTrigger.BriefCreate('水素能源模块的运行特效', block.center(), block.dimension);
}
;
export function Magma(block) {
    if (!CheckAllocation(block))
        return;
    EnergyAllocation(block, math_tools.Vector.CONSTANT_SOUTH);
    EnergyAllocation(block, math_tools.Vector.CONSTANT_NORTH);
    EnergyAllocation(block, math_tools.Vector.CONSTANT_EAST);
    EnergyAllocation(block, math_tools.Vector.CONSTANT_WEST);
}
;
